// @before-stub-for-debug-begin
#include <vector>
#include <string>
#include "commoncppproblem457.h"

using namespace std;
// @before-stub-for-debug-end

/*
 * @lc app=leetcode id=457 lang=cpp
 *
 * [457] Circular Array Loop
 */

// @lc code=start
class Solution {
public:
    bool circularArrayLoop(vector<int>& nums) {
    int n = nums.size();
    for (int i = 0; i < n; ++i) {
        std::vector<int> vs;
        int idx = (nums[i] + i + n) % n;
        vs.push_back(nums[i]);
        vector<bool> visited(n);
        visited[i] = true;
        while (!visited[idx]) {
        visited[idx] = true;
        vs.push_back(nums[idx]);
        idx = idx + nums[idx];
        idx = (idx + n) % n;
        }
        if (vs.size() >= 2 && idx == i) {
        int c1 = 0;
        for (auto v : vs) {
            c1 += v > 0 ? 1 : 0;
        }
        if (c1 == 0 || c1 == vs.size()) {
            return true;
        }
        }
    }
    return false;

        
    }
};
// @lc code=end

